package com.wzy.java;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class test23 {
    public static void main(String[] args) {
/*        Product prod1 = new Product(1, 1, new BigDecimal("15.5"), "面包", "零食");
        Product prod2 = new Product(2, 2, new BigDecimal("20"), "饼干", "零食");
        Product prod3 = new Product(3, 3, new BigDecimal("30"), "月饼", "零食");
        Product prod4 = new Product(4, 3, new BigDecimal("10"), "青岛啤酒", "啤酒");
        Product prod5 = new Product(5, 10, new BigDecimal("15"), "百威啤酒", "啤酒");*/

        List<Product> prodList = new ArrayList<>();
/*        prodList.add(prod1);
        prodList.add(prod2);
        prodList.add(prod3);
        prodList.add(prod4);
        prodList.add(prod5);*/


        for (int i = 0; i < 5000000; i++) {
            Product product = new Product(i, i + i, new BigDecimal(i), "面包" + i, "零食" + i);
            prodList.add(product);

        }

        long stime = System.currentTimeMillis();
        Map<Integer, List<Product>> prodMap = prodList.parallelStream().collect(Collectors.groupingBy(Product::getId));
        long etime = System.currentTimeMillis();
        System.out.printf("执行时长：%d 毫秒.", (etime - stime));
/*        prodMap.forEach((key,value)->{
            System.out.println(key+":"+value);
        });*/

//{"other":[{"category":"零食","id":3,"name":"月饼","num":3,"price":30},{"category":"啤酒","id":4,"name":"青岛啤酒","num":3,"price":10},{"category":"啤酒","id":5,"name":"百威啤酒","num":10,"price":15}],"3":[{"category":"零食","id":1,"name":"面包","num":1,"price":15.5},{"category":"零食","id":2,"name":"饼干","num":2,"price":20}]}



    }
}
